{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2e4812da",
   "metadata": {},
   "source": [
    "# NonlinearOptimizer\n",
    "\n",
    "## Overview\n",
    "\n",
    "The `NonlinearOptimizer` class in GTSAM is a the base class for (batch) nonlinear optimization solvers. It provides the basic API for optimizing nonlinear factor graphs, commonly used in robotics and computer vision applications.\n",
    "\n",
    "The primary purpose of the `NonlinearOptimizer` is to iteratively refine an initial estimate of a solution to minimize a nonlinear cost function. Specific optimization algorithms like Gauss-Newton, Levenberg-Marquardt, and Dogleg and implemented in derived class.\n",
    "\n",
    "## Mathematical Foundation\n",
    "\n",
    "The optimization process in `NonlinearOptimizer` is based on iterative methods that solve for the minimum of a nonlinear cost function. The general approach involves linearizing the nonlinear problem at the current estimate and solving the resulting linear system to update the estimate. This process is repeated until convergence criteria are met.\n",
    "\n",
    "The optimization problem can be formally defined as:\n",
    "\n",
    "$$\n",
    "\\min_{x} \\sum_{i} \\| \\phi_i(x) \\|^2\n",
    "$$\n",
    "\n",
    "where $x$ is the vector of variables to be optimized, and $\\phi_i(x)$ are the residuals of the factors in the graph.\n",
    "\n",
    "## Key Methods\n",
    "\n",
    "- The `optimize()` method is the core function of the `NonlinearOptimizer` class. It performs the optimization process, iteratively updating the estimate to converge to a local minimum of the cost function.\n",
    "- The `error()` method computes the total error of the current estimate. This is typically the sum of squared errors for all factors in the graph. Mathematically, the error can be expressed as:\n",
    "    $$\n",
    "    E(x) = \\sum_{i} \\| \\phi_i(x) \\|^2\n",
    "    $$\n",
    "    where $\\phi_i(x)$ represents the residual error of the $i$-th factor.\n",
    "- The `values()` method returns the current set of variable estimates. These estimates are updated during the optimization process.\n",
    "- The `iterations()` method provides the number of iterations performed during the optimization process. This can be useful for analyzing the convergence behavior of the optimizer.\n",
    "- The `params()` method returns the parameters used by the optimizer. These parameters can include settings like convergence thresholds, maximum iterations, and other algorithm-specific options.\n",
    "\n",
    "## Usage\n",
    "\n",
    "The `NonlinearOptimizer` class is typically not used directly. Instead, one of its derived classes, such as `GaussNewtonOptimizer`, `LevenbergMarquardtOptimizer`, or `DoglegOptimizer`, is used to perform specific types of optimization. These derived classes implement the `optimize()` method according to their respective algorithms.\n",
    "\n",
    "## Files\n",
    "\n",
    "- [NonlinearOptimizer.h](https://github.com/borglab/gtsam/blob/develop/gtsam/nonlinear/NonlinearOptimizer.h)\n",
    "- [NonlinearOptimizer.cpp](https://github.com/borglab/gtsam/blob/develop/gtsam/nonlinear/NonlinearOptimizer.cpp)\n",
    "- [NonlinearOptimizerParams.h](https://github.com/borglab/gtsam/blob/develop/gtsam/nonlinear/NonlinearOptimizerParams.h)\n",
    "- [NonlinearOptimizerParams.cpp](https://github.com/borglab/gtsam/blob/develop/gtsam/nonlinear/NonlinearOptimizerParams.cpp)"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
